package com.lwl.blog.web.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lwl.blog.web.entity.CommentEntity;
import com.lwl.blog.web.mapper.CommentMapper;
import com.lwl.blog.web.service.CommentService;
import com.lwl.blog.web.vo.CommentVo;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, CommentEntity> implements CommentService {

    @Override
    public boolean save(CommentEntity commentEntity) {
        commentEntity.setCreateTime(new Date());
        commentEntity.setStatus(1);
        return baseMapper.insert(commentEntity) > 0;
    }

    @Override
    public List<CommentVo> commentListByInvitataionId(Integer id) {
//        return baseMapper.commentListByInvitataionId(id);

        //1.根据帖子id查询，它下面的一级评论
        List<CommentVo> commentVoList = baseMapper.commentListByInvitataionId(1, id);

        //2.循环遍历，查询每一条评论下面的婚服信息
        for (CommentVo commentVo : commentVoList) {
            commentVo.setLikeStatus(0);
            commentVo.setLikeCount(0);
            Integer cid = commentVo.getCommentEntity().getId();
            // 评论下面的回复列表
            commentVo.setReplyList(baseMapper.commentListByInvitataionId(2, cid));
        }

        return commentVoList;
    }
}
